<?php
error_reporting(0);
$isadmin=1;
include_once '../comm/config.php';
include '../comm/checkpostandget.php';
include '../comm/msgset.php';
include 'check.php';
$ddusername=$_POST['ddusername']; 
$txje=$_POST['txje']; 
$id=$_POST['id']; 

$q = "select * from ".$BIAOTOU."tixian where Id=".$id;
$rs=mysql_query($q);
$num = mysql_num_rows($rs);
if(!$num)
{
	echo "错误：未找到该记录！";
	exit;
}
else
{
	while ($row = mysql_fetch_array($rs))
	{
		$zfb=$row["zfb"]; }
	$q = "update ".$BIAOTOU."tixian set txstate=1 where id=".$id;
	mysql_query($q);
	
	$q = "update ".$BIAOTOU."user set txstate=0,yitixian=yitixian+".$txje." where ddusername='$ddusername'";
	mysql_query($q);

	$sj= date("Y-m-d H:i:s");  
	$title="您有一笔提现申请已经受理完成";
	$msg_tixianok=str_replace("[ddusername]",$ddusername,$msg_tixianok);
	$msg_tixianok=str_replace("[txje]",$txje,$msg_tixianok);
	$msg_tixianok=str_replace("[zfb]",$zfb,$msg_tixianok);
	$insert = "INSERT into ".$BIAOTOU."msg(ddusername,title,content,addtime,senduser) values ('$ddusername','$title','$msg_tixianok','$sj','网站客服')";
	mysql_query($insert);
	$sql="select money,email,yitixian,tjr from ".$BIAOTOU."user where ddusername='".$ddusername."' limit 1";
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	$leave_money=$row[0];
	$email=$row['email'];
	$yitixian=$row['yitixian'];
	$tjrid=$row['tjr'];
	$insert = "INSERT into ".$BIAOTOU."mingxi(ddusername,shijian,je,addtime,memo,leave_money) values ('$ddusername','提现成功',-$txje,'$sj','支付宝帐号".$zfb."','".$leave_money."')";
	mysql_query($insert);
	if(SMTPOPEN=='on' && TIXIANSENDEMAIL==1){
        mail_send($email, WEBTITLE.'提现通知', $msg_tixianok);
    }
	
	if($tjrid>0 && $yitixian-$txje==0 && HYTXJL>0){
	    $sql="select ddusername from ".$BIAOTOU."user where Id=".$tjrid.' limit 1';
		$query=mysql_query($sql);
		$row=mysql_fetch_array($query);
		$tjrname=$row['ddusername'];
		if($tjrname!=''){
			$q = "update ".$BIAOTOU."user set money=money+".HYTXJL." where Id='$tjrid' limit 1";
	        mysql_query($q);
		    echo $insert = "INSERT into ".$BIAOTOU."mingxi(ddusername,shijian,je,addtime,memo) values ('$tjrname','好友提现奖励',".HYTXJL.",'$sj','您的好友".$ddusername."第一次成功提现，您获得".HYTXJL."元奖励')";
	        mysql_query($insert);
			$insert = "INSERT into ".$BIAOTOU."msg(ddusername,title,content,addtime,senduser) values ('$tjrname','好友提现奖励','您的好友".$ddusername."第一次成功提现，您获得".HYTXJL."元奖励','$sj','网站客服')";
	        mysql_query($insert);
		}
	}
}   
admin_log('确认提现');
header('Location: tixianlist.php');
mysql_close();

?>
